import request from '@/utils/request'
import {PaginatedData} from "../common"
import * as Types from './types'

//查询所有问题分类树
export async function getCategoryTree(): Promise<Types.Category[]> {
  return request.get('/question/category/tree')
}

//查询问题
export async function pageQuestion(req: Types.QuestionPageReq): Promise<PaginatedData<Types.QuestionPageResp>> {
  return request.post('/question/page', req)
}

export async function getQuestionDetail(id: number): Promise<Types.QuestionDetailResp> {
  return request.get('/question/detail?id=' + id)
}

// 问题回答
export async function pageQuestionAnswer(req: Types.QuestionAnswerPageReq):Promise<PaginatedData<Types.QuestionAnswerPageResp>> {
  return request.post('/question/answer/page', req)
}

export async function pageQuestionRepliesAnswer(req: Types.QuestionAnswerRepliesPageReq):Promise<PaginatedData<Types.QuestionAnswerRepliesPageResp>> {
  return request.post('/question/answer/replies/page', req)
}

export async function publishQuestionAnswer(req: Types.QuestionAnswerPublishReq):Promise<Object> {
  return request.post('/question/answer/publish', req)
}

// 提问
export async function saveQuestionDraft(req: Types.QuestionPublishReq):Promise<Object> {
  return request.post('/question/saveDraft', req)
}

export async function publishNewQuestion(req: Types.QuestionPublishReq):Promise<Object> {
  return request.post('/question/publish', req)
}